<?php 

// returns a string of error messages if invalid user input found or an empty string if no errors
function validate_input() {
   $errorMessages = "";
   
   // error check the users name
   if (!isset($_POST['name']) || empty($_POST['name'])) {
      $errorMessages .= "Your name is required<br />";
   } elseif (!preg_match('/^[A-Za-z ]+$/', $_POST['name'])) {
      $errorMessages .= "Your name may only be letters or the blank character<br />";
   }
   
   // error check everything else
   
   
   return $errorMessages;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
ID: 1130000
File:  C:\wamp\www\labs\lab7\lab7validate.php
Honor Code: We pledge that this code represents our own work: name(s)
-->
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>COMP334 Lab 7: Validate</title>
<meta name="description" content="COMP334 Lab 7: Form Validation" />
<meta name="keywords" content="comp, bzu,334" />
<meta name="author" content="Your Names" />
</head>

<body>
<h1>Lab 7: Validate</h1>

<?php

// Check for errors in the user input
$errors = validate_input();
if ($errors != "") {
   echo "<p>$errors</p>";
}
else {
   //user input validates, display a dump of the POST variables 
   echo "<pre>";
   print_r($_POST);
   echo "</pre>";
}
 ?>
<p>Click here to return to <a href="lab7input.php">lab7input.php</a> page</p>

</body>
</html>

